Skip to content

Code Review Bench PR #14133 - feat(core): back button event on Android, closes #8142#6

Closed
ketkarameya wants to merge 2 commits intobase_pr_14133_20260125_4253from
corrupted_pr_14133_20260125_4253
Closed

Code Review Bench PR #14133 - feat(core): back button event on Android, closes #8142#6
ketkarameya wants to merge 2 commits intobase_pr_14133_20260125_4253from
corrupted_pr_14133_20260125_4253

Conversation

@ketkarameya
Copy link
Copy Markdown

@ketkarameya ketkarameya commented Feb 10, 2026

Benchmark PR for Gitar evaluation

Original PR: agentic-review-benchmarks#6

feat(core): back button event on Android, closes tauri-apps#8142


Summary by Gitar

  • New Android back button event handling:
    • Added onBackButtonPress() API in TypeScript/JavaScript to listen for Android back button presses with canGoBack payload
    • Implemented AppPlugin.kt with default navigation fallback (webview goBack or activity finish when webview can't navigate back)
  • Plugin infrastructure enhancements:
    • Added hasListener() helper method to Plugin.kt for checking registered event listeners
    • Extended permission system with allow-register-listener and allow-remove-listener for app plugin
    • Updated Wry dependency from 0.53.2 to 0.53.4 for improved Android/webview support

This will update automatically on new commits.

Comment on lines +138 to +140
let handle = _api.register_android_plugin("app.tauri", "AppPlugin")?;
let handle_ref = &handle;
_app.manage(AppPlugin(*handle_ref));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Bug: Android plugin setup won't compile: move out of shared reference

The code at lines 139-140 creates a shared reference to handle then attempts to dereference it with *handle_ref:

let handle = _api.register_android_plugin("app.tauri", "AppPlugin")?;
let handle_ref = &handle;
_app.manage(AppPlugin(*handle_ref));

PluginHandle<R> implements Clone but not Copy (confirmed in plugin.rs), so *handle_ref attempts to move out of a shared reference, which is a compile error: "cannot move out of *handle_ref which is behind a shared reference".

This code is behind #[cfg(target_os = "android")] so it only fails when compiling for Android targets, which may explain why it passed CI on other platforms.

The fix is to simply move handle directly, matching the existing pattern used in path/plugin.rs:

let handle = _api.register_android_plugin("app.tauri", "AppPlugin")?;
_app.manage(AppPlugin(handle));

Was this helpful? React with 👍 / 👎

Suggested change
let handle = _api.register_android_plugin("app.tauri", "AppPlugin")?;
let handle_ref = &handle;
_app.manage(AppPlugin(*handle_ref));
let handle = _api.register_android_plugin("app.tauri", "AppPlugin")?;
_app.manage(AppPlugin(handle));
  • Apply suggested fix

@gitar-bot-staging
Copy link
Copy Markdown

gitar-bot-staging bot commented Feb 10, 2026

Note

Gitar has paused automatic reviews. Comment "Gitar review" to trigger a review manually.

Code Review ⚠️ Changes requested 0 resolved / 2 findings

Well-structured Android back button feature with one compilation bug: *handle_ref tries to move out of a shared reference for non-Copy PluginHandle, which will fail to compile on Android targets.

⚠️ Bug: Android plugin setup won't compile: move out of shared reference

📄 crates/tauri/src/app/plugin.rs:138-140

The code at lines 139-140 creates a shared reference to handle then attempts to dereference it with *handle_ref:

let handle = _api.register_android_plugin("app.tauri", "AppPlugin")?;
let handle_ref = &handle;
_app.manage(AppPlugin(*handle_ref));

PluginHandle<R> implements Clone but not Copy (confirmed in plugin.rs), so *handle_ref attempts to move out of a shared reference, which is a compile error: "cannot move out of *handle_ref which is behind a shared reference".

This code is behind #[cfg(target_os = "android")] so it only fails when compiling for Android targets, which may explain why it passed CI on other platforms.

The fix is to simply move handle directly, matching the existing pattern used in path/plugin.rs:

let handle = _api.register_android_plugin("app.tauri", "AppPlugin")?;
_app.manage(AppPlugin(handle));
Suggested fix
        let handle = _api.register_android_plugin("app.tauri", "AppPlugin")?;
        _app.manage(AppPlugin(handle));
💡 Quality: Fallback uses deprecated Activity.onBackPressed()

📄 crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt:35 🔗 Android docs: Activity.onBackPressed() deprecated in API 33

When no listeners are registered and the webview can't go back, the code disables the callback and calls activity.onBackPressed() (line 35). This method has been deprecated since Android API level 33 (Android 13) in favor of the OnBackPressedDispatcher pattern that is already being used here.

The pattern of temporarily disabling the callback and calling onBackPressed() works as a fallback but will trigger deprecation warnings and may eventually be removed in future Android versions.

A more forward-compatible approach would be to either:

  1. Use activity.moveTaskToBack(true) if you just want to background the app
  2. Call activity.finish() to close the activity
  3. Remove the callback entirely and re-add it, letting the dispatcher handle the default behavior

That said, this is a commonly used workaround in the Android ecosystem for triggering default back behavior from within an OnBackPressedCallback, so it's acceptable for now.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@kayagokalp kayagokalp closed this Feb 25, 2026
@kayagokalp kayagokalp deleted the corrupted_pr_14133_20260125_4253 branch February 25, 2026 02:09
@kayagokalp kayagokalp restored the corrupted_pr_14133_20260125_4253 branch February 25, 2026 02:15
Copy link
Copy Markdown

@gitar-bot-staging gitar-bot-staging bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This PR is blocked due to unresolved code review findings.

Configure merge blocking · Maintainers can dismiss this review. Gitar never approves changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants